//
//  YTTHeaderView.m
//  跑圈儿
//
//  Created by dllo on 16/4/28.
//  Copyright © 2016年 唐康. All rights reserved.
//

#import "YTTHeaderView.h"
#import "UILabel+YTTLable.h"

//左右边界
static CGFloat inset = 20;
//label高
static CGFloat labelHeight = 40;
//温度的label高
static CGFloat tempLabelHeight = 110;


@implementation YTTHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        //添加 button的frame
        CGRect frame = CGRectMake(0, inset,labelHeight, labelHeight);
        self.menuButton = [[UIButton alloc] initWithFrame:frame];
        [self.menuButton setImage:[UIImage imageNamed:@"homepage_leftitem"] forState:UIControlStateNormal];
        [self addSubview:self.menuButton];
        
        //添加 cityLabel
        self.cityLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, inset, (YTTScreenW), labelHeight)];
        self.cityLabel.text = @"Loading";
        self.cityLabel.textAlignment = NSTextAlignmentCenter;
        self.cityLabel.textColor = [UIColor whiteColor];
        [self addSubview:self.cityLabel];
        
        //添加iconView
        self.iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"999"]];
        CGRect frameIcon = self.iconView.frame;
        frameIcon = CGRectMake(inset, YTTScreenH - inset - 2 * labelHeight -tempLabelHeight - 80, labelHeight, labelHeight);
        self.iconView.frame = frameIcon;
        [self addSubview:self.iconView];
        
        //添加 conditionsLabel
        CGRect conditionsLabeFrame = CGRectMake(inset + labelHeight, YTTScreenH - inset - 2*labelHeight - tempLabelHeight - 80, YTTScreenW - 2 * inset - labelHeight, labelHeight);
        self.conditionsLabel = [UILabel setLabelWithFrame:conditionsLabeFrame];
        self.conditionsLabel.text = @"Clear";
        [self addSubview:self.conditionsLabel];
        
        //添加temperatureLabel
        self.temperatureLabel = [[UILabel alloc]initWithFrame:CGRectMake(inset, YTTScreenH -inset-labelHeight-tempLabelHeight - 80, tempLabelHeight, tempLabelHeight)];
        self.temperatureLabel.text = @"0˚";
        self.temperatureLabel.font = [UIFont fontWithName:@"HelveticaNeue-BoldItalic" size:95];
        self.temperatureLabel.textColor = [UIColor whiteColor];
        [self addSubview:self.temperatureLabel];
        
        //添加hiloLabel
        self.hiloLabel = [[UILabel alloc]initWithFrame:CGRectMake(inset, YTTScreenH -inset-labelHeight - 80, YTTScreenW -inset * 2, labelHeight)];
        self.hiloLabel.text = @"0˚/ 0˚";
        self.hiloLabel.textColor = [UIColor whiteColor];
        self.hiloLabel.font = [UIFont systemFontOfSize:30];
        [self addSubview:self.hiloLabel];
        
        //判断星期几
        NSInteger year,month,day,hour,min,sec,week;
        NSString *weekStr=nil;
        
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        NSDate *now = [NSDate date];;
        NSDateComponents *comps = [[NSDateComponents alloc] init];
        NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
        NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
        
        comps = [calendar components:unitFlags fromDate:now];
        year = [comps year];
        week = [comps weekday];
        month = [comps month];
        day = [comps day];
        hour = [comps hour];
        min = [comps minute];
        sec = [comps second];
        
        if(week == 1)
        {
            weekStr=@"星期天";
        }else if(week   == 2){
            weekStr=@"星期一";
            
        }else if(week == 3){
            weekStr=@"星期二";
            
        }else if(week == 4){
            weekStr=@"星期三";
            
        }else if(week == 5){
            weekStr=@"星期四";
            
        }else if(week == 6){
            weekStr=@"星期五";
            
        }else if(week == 7){
            weekStr=@"星期六";
            
        }
        else {
            NSLog(@"error!");
        }
        
    
        
        CGRect aqiLabelFrame = CGRectMake(inset, labelHeight + 2 * inset - 10, 4 * labelHeight, labelHeight + 50);
        self.aqiLabel = [UILabel setLabelWithFrame:aqiLabelFrame];
        self.aqiLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
        self.aqiLabel.text = weekStr;
        self.aqiLabel.font =[ UIFont systemFontOfSize:22];
        
        [self addSubview:self.aqiLabel];
        
        //添加locLabel
        CGRect locLabelFrame = CGRectMake(YTTScreenW - inset - 3 * labelHeight, labelHeight + 3 * inset - 10, labelHeight * 3.5, labelHeight);
        self.locLabel = [UILabel setLabelWithFrame:locLabelFrame];
        self.locLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:15];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        
        
        NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
        NSString *newStr = [dateStr substringToIndex: 11];
        self.locLabel.text = newStr;
        self.locLabel.font =[ UIFont systemFontOfSize:20];
        [self addSubview:self.locLabel];
        
        
    }
    
    return self;
}










































/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
